

#include <stdio.h>
#include "comm.h"
#include "thread.h"



void showSys(sysConf *sys)
{
    int i = 0;
    printf("com ============\n");
    for(i=0; i<sys->cnt_com; i++){
        printf("com[%d]:num = %d, baud = %d , stop = %d , parity = %c, databits  =%d\n",
               i, sys->com[i].num, sys->com[i].baud, sys->com[i].stop, sys->com[i].parity, sys->com[i].databits);
    }
    
    printf("net ============\n");
    for(i=0; i<sys->cnt_net; i++){
        printf("server[%d]: ip is %s , port = %d , protocal = %d \n", i, sys->net[i].ip, sys->net[i].port, sys->net[i].protocal);
    }

    
}

int main(int argc, char *argv[])
{
    sysConf sys;
    int ret;

    #ifndef  UART_TEST
    if(SysInit(&sys) < 0){
        zc_debug("sysinit faild ");
        return -1;
    }
    zc_debug("====sys init OK ");

    ret = pthread_create(&sys.pid_of_net, NULL, NetStateThread, &sys);
    if(ret < 0){
        printf("create NetStateThread faild \n");
        return -1;
    }

    ret = pthread_create(&sys.pid_of_com, NULL, UartHandThread, &sys);
    if(ret < 0){
        printf("create UartHandThread faild \n");
        return -1;
    }


    sys.status = SYS_RUNNING;

    showSys(&sys);
    NetHandleThread(&sys);
    #else
    int num = 200;
    if(argc == 2){
        num = atoi(argv[1]);
    }
    
    Uart1Test(num);
    #endif 
}